cmake_minimum_required(VERSION 3.22)
project(Sofa.Component.Mapping.NonLinear LANGUAGES CXX)

set(SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR "src/sofa/component/mapping/nonlinear")

set(HEADER_FILES
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/config.h.in
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/init.h
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/AreaMapping.h
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/AreaMapping.inl
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/BaseNonLinearMapping.h
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/BaseNonLinearMapping.inl
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/DistanceFromTargetMapping.h
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/DistanceFromTargetMapping.inl
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/DistanceMapping.h
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/DistanceMapping.inl
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/DistanceMultiMapping.h
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/DistanceMultiMapping.inl
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/NonLinearMappingData.h
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/RigidMapping.h
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/RigidMapping.inl
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/SquareDistanceMapping.h
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/SquareDistanceMapping.inl
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/SquareMapping.h
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/SquareMapping.inl
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/VolumeMapping.h
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/VolumeMapping.inl
)

set(SOURCE_FILES
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/init.cpp
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/AreaMapping.cpp
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/DistanceFromTargetMapping.cpp
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/DistanceMapping.cpp
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/DistanceMultiMapping.cpp
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/RigidMapping.cpp
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/SquareDistanceMapping.cpp
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/SquareMapping.cpp
    ${SOFACOMPONENTMAPPINGNONLINEAR_SOURCE_DIR}/VolumeMapping.cpp
)

sofa_find_package(Sofa.Simulation.Core REQUIRED)

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Simulation.Core)

sofa_create_package_with_targets(
    PACKAGE_NAME ${PROJECT_NAME}
    PACKAGE_VERSION ${Sofa_VERSION}
    TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES
    INCLUDE_SOURCE_DIR "src"
    INCLUDE_INSTALL_DIR "${PROJECT_NAME}"
)

# Tests
# If SOFA_BUILD_TESTS exists and is OFF, then these tests will be auto-disabled
cmake_dependent_option(SOFA_COMPONENT_MAPPING_NONLINEAR_BUILD_TESTS "Compile the automatic tests" ON "SOFA_BUILD_TESTS OR NOT DEFINED SOFA_BUILD_TESTS" OFF)
if(SOFA_COMPONENT_MAPPING_NONLINEAR_BUILD_TESTS)
    enable_testing()
    add_subdirectory(tests)
endif()
